package cn.iocoder.yudao.module.shop.convert.item;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.shop.controller.admin.itemconsume.ShopItemConsumeRespVO;
import cn.iocoder.yudao.module.shop.dal.dataobject.order.ShopOrderItemDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.shop.controller.admin.item.vo.*;
import cn.iocoder.yudao.module.shop.dal.dataobject.item.ShopItemDO;

/**
 * 店铺项目 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface ShopItemConvert {

    ShopItemConvert INSTANCE = Mappers.getMapper(ShopItemConvert.class);

    ShopItemDO convert(ShopItemCreateReqVO bean);

    ShopItemDO convert(ShopItemUpdateReqVO bean);

    ShopItemRespVO convert(ShopItemDO bean);

    default ShopItemRespVO convert(ShopItemDO bean, List<ShopItemConsumeRespVO> consumeRespVOList){
        ShopItemRespVO shopItemRespVO = convert(bean);
        shopItemRespVO.setConsumeItemList(consumeRespVOList);

        return shopItemRespVO;
    }

    List<ShopItemRespVO> convertList(List<ShopItemDO> list);

    default List<ShopItemRespVO> convertList(List<ShopItemDO> shopItemDOList, List<ShopItemConsumeRespVO> shopItemConsumeRespVOList){
        List<ShopItemRespVO> list = convertList(shopItemDOList);
        Map<Long, List<ShopItemConsumeRespVO>> mapList = CollectionUtils.convertMultiMap(shopItemConsumeRespVOList, ShopItemConsumeRespVO::getItemId);
        list.forEach(shopItemRespVO -> {
            shopItemRespVO.setConsumeItemList(mapList.get(shopItemRespVO.getId()));
        });

        return list;
    }

    PageResult<ShopItemRespVO> convertPage(PageResult<ShopItemDO> page);

    default PageResult<ShopItemRespVO> convertPage(PageResult<ShopItemDO> page, List<ShopItemConsumeRespVO> consumeRespVOList){
        PageResult<ShopItemRespVO> pageResult = convertPage(page);
        List<ShopItemRespVO> newList = convertList(page.getList(), consumeRespVOList);
        pageResult.setList(newList);

        return pageResult;
    }

    List<ShopItemExcelVO> convertList02(List<ShopItemDO> list);

    default Map<Long, ShopItemRespVO> convertShopItemMap(List<ShopItemDO> list){
        ArrayList<ShopItemRespVO> list1 = new ArrayList<>(list.size());
        for(ShopItemDO shopItemDO: list)
        {
            list1.add(convert(shopItemDO));
        }
        Map<Long, ShopItemRespVO> shopItemRespVOMap = CollectionUtils.convertMap(list1, ShopItemRespVO::getId);

        return shopItemRespVOMap;
    }

}
